package domain

import "time"

// Order
// json 序列化与反序列化名称，omitempty如果为空，则从JSON中忽略,json:"-"忽略该字段(不会出现在JSON中)
// gorm：column 数据库对应字段
// form 用于HTML表单数据和URL查询参数
// binding 用于请求参数验证的标签
type Order struct {
	Id         uint      `json:"id" form:"id" gorm:"column:id" binding:""`
	UserId     uint      `json:"userId" form:"userId" gorm:"column:user_id" binding:""`
	ProductId  uint      `json:"productId" form:"productId" gorm:"column:product_id" binding:""`
	OrderNum   string    `json:"orderNum" form:"orderNum" gorm:"column:order_num" binding:"required,min=12,max=50"`
	Num        int16     `json:"num,omitempty" form:"num" gorm:"column:num" binding:"required,min=12,max=50"`
	Price      float64   `json:"mobile,omitempty" form:"mobile" gorm:"column:phone" binding:"required,phone"`
	CreateTime time.Time `json:"createTime" form:"createTime" gorm:"column:create_time" binding:"required,gte=0,lte=150"`
	UpdateTime time.Time `json:"updateTime" form:"updateTime" gorm:"column:update_time" binding:"required"`
}

func (u Order) getName() string {
	if u.OrderNum != "" {
		return u.OrderNum
	}
	return ""
}
